<!-- News.html -->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>竞赛</title>
		<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
		<link rel="stylesheet" type="text/css" href="../../css/base.css"/>
		<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
		<style>
			.base_back_icon1 {
				height: 20px;
				position: absolute;
				top: 50%;
				right: 10px;
				margin-top: -11px;
			}
			.menu {
				float: right;
				margin-right: 35px
			}
			.menu li {
				float: left; /* 往左浮动 */
				line-height: 44px;
				margin: 0 4px;
				height: 44px;
			}
			.menu li img {
				height: 20px;
				vertical-align: middle;
			}
			.menu li label {
				font-size: 12px;
				/*margin-bottom: 12px;*/
			}
			.base_navigation_bar span {
				left: 38%;
				width: 159px;
				max-width: 200px;
				margin-left: 18px;
			}
			.base_left_item, .base_right_item {
				width: 37px;
			}
			.base_right_reddiv{
			    top: 15px;
			    right: 8px;
			    width: 5px;
			    height: 5px;
			}
		</style>
	</head>
	<body>
		<div class="base_style_color " id='BarAppearance' style="height: 22px;width: 100%"></div>
		<div class="base_navigation_bar base_style_color base_navigation_item_bar" style="position: fixed;left: 0px;top: 20px;">
			<div class="base_navigation_bar base_style_color base_navigation_item_bar">
				<a class="base_left_item" href="#" onclick="back()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
				<!--<a class="base_left_item " style="width: 37px;font-size: 18px" href="#" onclick="backClick()">关闭 </a>-->
				<a class="base_left_item " href="#" > <img class="base_back_icon"  style="margin-left: 25px;" src="../../image/competition_close.png" alt="" onclick="backClick()"> </a>
				<span id="title"></span>
				<ul class="menu">
					<li>
						<img class="" src="../../image/competition_score.png" alt="">
						<label id="score"></label>
					</li>
					<li>
						<img class="" src="../../image/competition_order.png" alt="">
						<label id="order"></label>
					</li>
				</ul>
				<a class="base_right_item" onclick="openF()"><div id="redPoint_xuexi_div" class="redPointMessage base_right_reddiv" ></div><img class="base_back_icon1" src="../../image/competition_more.png" alt=""></a>
			</div>
		</div>
	</body>
	<script src="../../script/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script type="text/javascript">
		var href_html = '';
		var title_html = '';
		var nameArr = new Array();
		var markisshow = false;
		var isreddot='0';//0:有红点  1：无红点
		apiready = function() {
		     isRedDot();
			showNewsFrame();
			setInterval('getFrameUrl()', 500);
			addFrameLiten();
			keyback();
			addNotifi()
			getOrderAndScore();
		}
		//是否显示小红点
		function isRedDot(){
		
		     isreddot = $api.getStorage('isreddot');
		   
		     if(isreddot ==1&&$api.getStorage('isreddot1') ==1){
		        $("#redPoint_xuexi_div").hide();
		     }else{
		       $("#redPoint_xuexi_div").show();
		       
		     }
		}
		//获取用户积分和排名
		function getOrderAndScore() {
			var param = {
				types : 61, //报名类型 ts2_apply_cate id
				uid : $api.getStorage('cfnetppuid'), //用户id
				cateid : 3, //第几届学霸赛
			};
			cfnetppPOST(url_getUserRank, param, false, function(data, status) {
				if (status == 'success') {
					if (data.code == 200) {
						$('#order').html(data.data.paiming);
						$('#score').html(data.data.jifen);
					} else {
						$('#order').html('0');
						$('#score').html('0');
					}
				} else {
					$('#order').html('0');
					$('#score').html('0');
				}
			});
		}

		function addNotifi() {
			api.addEventListener({
				name : 'CompetitionCategoryNotifi'
			}, function(ret, err) {
				//coding...
				var index = ret.value.currentCategorytype;
				openNewFrame(index);
			});
		}

		function openNewFrame(index) {
	         
         
			var y = $('.base_navigation_bar').height() + 22;
			var h = api.winHeight - y;
			//			var url1 = isfreelogin(1, 'http://test.m.cfnet.org.cn/index.php/match/index/contest');
			//			var url2 = isfreelogin(1, 'http://test.m.cfnet.org.cn/index.php/match/index/index');
			//			var url4 = isfreelogin(1, 'http://test.m.cfnet.org.cn/index.php/match/index/minefootprint');
			var url1 = isfreelogin(1, url_XueBacontest);
			var url2 = isfreelogin(1, url_XueBaindex);
			var url4 = isfreelogin(1, url_XueBaminefootprint);
			//			var url4 = isfreelogin(1, 'http://test.m.cfnet.org.cn/index.php/match/index/mineteam');
			var url_Competition1 = '';
			var num = parseInt(index)
			switch (num) {
				case 0:
					break;
				case 1:
					url_Competition1 = url1;
					break;
				case 2:
					url_Competition1 = url2;
					break;
				case 3:
					url_Competition1 = url3;
					break;
				case 4:
					url_Competition1 = url4;
					break;
			     case 5:
			        isRedDot();
					  onShareClick();
					return;
				 case 6:
				    isRedDot();
				     api.openWin({useWKWebView:true,
		                name : 'suggestBack',
		                url : '../Practice_Mine/suggestBack.html',
		                animation:{
		                    type:"none",                //动画类型（详见动画类型常量）
		                    subType:"from_right",       //动画子类型（详见动画子类型常量）
		                    duration:300                //动画过渡时间，默认300毫秒
		                },
		                slidBackEnabled: false,
		             });
					
					return;
				default:
					break;
			}
			api.openFrame({
				name : 'CompetitionFrame',
				url : url_Competition1,
				rect : {
					x : 0,
					y : y,
					w : 'auto',
					h : h
				},
				progress : {//设置进度条类型和样式
					type : 'page',
					color : '#18b4ed'
				},
				scaleEnabled : true,
				//				reload : true
			});
		}
   
		function openF() {
			if (markisshow) {
				markisshow = false;
				api.setFrameAttr({
					name : 'Competition_SelectFrame',
					hidden : true
				});
			} else {
			
				markisshow = true;
				var y = $('.base_navigation_bar').height() + 22;
				var x=api.winWidth-105;
				api.openFrame({
					name : 'Competition_SelectFrame',
					url : 'Competition_SelectFrame.html',
					rect : {
						x : x,
						y : y,
						w : 100,
						h : 180,
//						marginRight : 2
					},
					bounces : false,
				});
				api.setFrameAttr({
					name : 'Competition_SelectFrame',
					hidden : false
				});
			}
		}

		//远程页面动作监听
		function addFrameLiten() {
			api.setFrameClient({
				frameName : 'CompetitionFrame'
			}, function(ret, err) {
				href_html = ret.url;
				switch (ret.state) {
					case 0:
						break;
					case 1:
						break;
					case 2:
						break;
					case 3:
						$('#title').html(ret.title);
						break;
					case 4:
						break;
					default:
						break;
				}
			});
			api.addEventListener({
				name : 'getUrl'
			}, function(ret, err) {
				if (ret && ret.value) {
					var value = ret.value;
					$('#title').html(value.title);
				}
			});
		}

		//打开新页面
		function showNewsFrame() {
			var y = $('.base_navigation_bar').height() + 22;
			var h = api.winHeight - y;
			//			var url_Competition = isfreelogin(1, 'http://test.m.cfnet.org.cn/index.php/match/index/contest');
			var url_Competition = isfreelogin(1, url_XueBacontest);
			api.openFrame({
				name : 'CompetitionFrame',
				url : url_Competition,
				rect : {
					x : 0,
					y : y,
					w : 'auto',
					h : h
				},
				progress : {//设置进度条类型和样式
					type : 'page',
					color : '#18b4ed'
				},
				scaleEnabled : true,
				//				reload : true
			});
		}

		//得到远程页面地址
		function getFrameUrl() {
			var script = "api.sendEvent({name: 'getUrl', extra: {url: window.location ,title: document.title}});";
			api.execScript({
				frameName : 'CompetitionFrame',
				script : script
			});
		}

		//远程页面返回
		function back() {
			api.historyBack({
				frameName : 'CompetitionFrame'
			}, function(ret, err) {
				if (!ret.status) {
					backClick();
				}
			});
		}

		//安卓系统返回键监听
		function keyback() {
			api.addEventListener({
				name : 'keyback'
			}, function(ret, err) {
				//coding...
				back()
			});
		}

		function backClick() {
			api.closeWin({
			});
		}
		 //分享
	function onShareClick(){
            //分享的信息
	var url="http://m.xueba.cfnet.org.cn/index.php/match/index/mineteam?buid="+$api.getStorage('cfnetppuid');
	var title = "学霸赛榜单";
	var description = "长风网";
	var thumbUrlQQ = "http://ossimg.cfnet.org.cn/img/20170603/112667-1496458368-70714.png";
	var thumbUrlWV = "widget://image/logosmall.png";
	    var dialogBox = api.require('dialogBox');
	    dialogBox.actionMenu ({
	    tapClose:true,
	    rect:{
	        h: 208
	    },
	    texts:{
	         cancel: '取消'
	    },
	    items:[
	    {
	        text: '分享到微信',
	        icon: 'widget://image/icon_weixin.png'
	    },
	    {
	        text: '分享到朋友圈',
	        icon: 'widget://image/icon_pengyouquan.png'

	    },
	    {
	        text: '分享到手机QQ',
	        icon: 'widget://image/icon_qq.png'
	    },
	    {
	        text: '分享到QQ空间',
	        icon: 'widget://image/icon_kongjian.png'
	    }
	    ],
	    styles:{
	        bg:'#F0F0F0',
	        column: 4,
	        itemText: {
	            color: '#000',
	            size: 12,
	            marginT:8
	        },
	        itemIcon:{
	            size:60
	        },
	        cancel:{
		        // bg:'widget://image/icno_share_buttom.png',
	            color:'#535353',
	            h: 38 ,
	            size: 14
	        }
	    }
	  }, function(ret){

	   var eventType= ret.eventType;//判断类型
	   var index=ret.index;
	    if(eventType=='cancel'){//关闭
	      dialogBox.close({ dialogName: 'actionMenu'});
	       return;
	    }
		 if(index==2||index==3){

		   var qq = api.require('qq');
		   qq.installed(function(ret, err) {

		    if (ret.status) {
		     if(index==2){//qq

			  qq.shareNews({
			    url: url,
			    type:'QFriend',
			    title: title,
			    description: description,
			    imgUrl: thumbUrlQQ
			   },function(ret,err){
			     dialogBox.close({  dialogName: 'actionMenu'});
                if (ret.status) {

			        api.toast({
		                msg:'分享成功QQ'
	                });
				    } else {
						if (err.code == -4) {
							api.toast({
				                msg:'用户取消分享'
			                });
						}else if (err.code == 10000) {
							api.toast({
				                msg:'QQ空间分享不支持文本类型分享'
			                });
						}else if (err.code == 10001) {
							api.toast({
				                msg:'QQ空间分享不支持图片类型分享'
			                });
						}else if (err.code == 10009) {
							api.toast({
				                msg:'当前设备未安装QQ客户端'
			                });
						}else{
							api.toast({
				                msg:'分享失败QQ'
			                });
						}
				    }
	            });
		        }else if(index==3) {//qq空间
		         qq.shareNews({
				    url: url,
				    type:'QZone',
				    title: title,
				    description: description,
				    imgUrl: thumbUrlQQ
				   },function(ret,err){
				     dialogBox.close({  dialogName: 'dialogBox'});
					if (ret.status) {

			        api.toast({
		                msg:'分享成功QQ空间'
	                });
				    } else {
						if (err.code == -4) {
							api.toast({
				                msg:'用户取消分享'
			                });
						}else if (err.code == 10000) {
							api.toast({
				                msg:'QQ空间分享不支持文本类型分享'
			                });
						}else if (err.code == 10001) {
							api.toast({
				                msg:'QQ空间分享不支持图片类型分享'
			                });
						}else if (err.code == 10009) {
							api.toast({
				                msg:'当前设备未安装QQ客户端'
			                });
						}else{
							api.toast({
				                msg:'分享失败QQ空间'
			                });
						}
				    }
	            });
		         }
		          return;
		    } else {

		       dialogBox.close({  dialogName: 'actionMenu'});
	      	alert("没有安装QQ");
		     // $("#passFailCount").show();
			    //  $("#title_text").html('没有安装QQ');

		    }
		});
		  }
		 if(index==0||index==1){
		   var wx = api.require('wx');
		   wx.isInstalled(function(ret, err) {
		    if (ret.installed) {
		     if(index==0){//微信
		     wx.shareWebpage({
			    apiKey: '',
			    scene: 'session',
			    title: title,
			    description: description,
			    thumb: thumbUrlWV,
			    contentUrl: url
			     }, function(ret, err) {
			        dialogBox.close({
			        	dialogName: 'actionMenu'});
				    if (ret.status) {

				        api.toast({
			                msg:'分享成功微信好友'
		                });
				    } else {
						api.toast({
			                msg:'分享失败微信好友'
		                });
				    }
			     });
		      }else if(index==1){//朋友圈
		      wx.shareWebpage({
			    apiKey: '',
			    scene: 'timeline',
			    title: title,
			    description: description,
			    thumb: thumbUrlWV,
			    contentUrl: url
				}, function(ret, err) {
				    dialogBox.close({  dialogName: 'actionMenu'});
				    if (ret.status) {

				       api.toast({
			                msg:'分享成功朋友圈'
		                });
				    } else {
						api.toast({
			                msg:'分享失败朋友圈'
		                });
				    }
				});

		        }

		    } else {
		       dialogBox.close({  dialogName: 'actionMenu'});
		    	alert("没有安装微信");
//			   $("#passFailCount").show();
//				       $("#title_text").html('没有安装微信');


		    }
		});
		}

});

}
   
	</script>
</html>